package applet.attendee;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;

import data.CMSRes;
import data.account.attendee.AttendeeAccount;
import applet.attendee.locked.CMSAttendeeLockedView;
import applet.attendee.unlocked.CMSAttendeeUnlockedView;
import applet.view.BaseCMSView;
import applet.view.CMSViewController;

public class CMSAttendeeView extends BaseCMSView
{
	private AttendeeAccount attendee;
	public AttendeeAccount attendee() { return attendee; }
	
	private CMSViewController attendeeViewController;
	public CMSViewController attendeeViewController() { return attendeeViewController; }
	
	public CMSAttendeeView(AttendeeAccount attendee)
	{
		this.attendee = attendee;
		
		JPanel view = new JPanel(new BorderLayout());
		view.setBorder(new BevelBorder(BevelBorder.RAISED));
			JPanel topBar = new JPanel(new BorderLayout());
			topBar.setBorder(new EmptyBorder(10, 20, 10, 10));
			topBar.setBackground(CMSRes.Colors.get("Theme Color Medium"));
				
				JLabel usernameLabel = new JLabel("Welcome, " + attendee.userID());
				usernameLabel.setFont(usernameLabel.getFont().deriveFont(Font.BOLD));
				topBar.add(usernameLabel, BorderLayout.WEST);
				
				JButton logoutButton = new JButton("Log Out");
				logoutButton.setPreferredSize(new Dimension(150, 30));
				logoutButton.addActionListener(new LogOutListener());
				topBar.add(logoutButton, BorderLayout.EAST);
			
			view.add(topBar, BorderLayout.NORTH);

				if(attendee.checkedIn())
					attendeeViewController = new CMSViewController(new CMSAttendeeLockedView(this));
				else
					attendeeViewController = new CMSViewController(new CMSAttendeeUnlockedView(this));
			
			view.add(attendeeViewController, BorderLayout.CENTER);
			
		setView(view);
	}
	
	public void checkIn()
	{
		
	}
	
	public void logOut()
	{
		viewController().deferToDefaultView();
	}
	
	private class LogOutListener implements ActionListener {
		@Override public void actionPerformed(ActionEvent e) { logOut(); } }
}